package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.db.domain.system.MpCashApply;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.service.IMpCashApplyService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 用户申请提现记录Controller
 * 
 * @author ruoyi
 * @date 2022-07-23
 */
@Api(value = "用户申请提现记录",tags ="用户申请提现记录")
@RestController
    @RequestMapping("/cash/apply")
public class MpCashApplyController extends BaseController
{
    private static Logger log = LoggerFactory.getLogger(MpCashApplyController.class);
    @Autowired
    private IMpCashApplyService mpCashApplyService;

    /**
     * 查询用户申请提现记录列表
     */
    @ApiOperation(value = "查询用户申请提现记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpCashApply",value="用户申请提现记录",paramType="form")
    })
    @RequiresPermissions("system:apply:list")
    @GetMapping("/list")
    public TableDataInfo list(MpCashApply mpCashApply)
    {
        try {
            startPage();
            List<MpCashApply> list = mpCashApplyService.selectMpCashApplyList(mpCashApply);
            return getDataTable(list);
        }catch (Exception e){
            log.error("用户申请提现记录发生异常",e);
        }
        return null;
    }

    /**
     * 导出用户申请提现记录列表
     */
    @ApiOperation(value = "导出用户申请提现记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpCashApply",value="用户申请提现记录",dataType="MpCashApply")
    })
    @RequiresPermissions("system:apply:export")
    @Log(title = "用户申请提现记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody MpCashApply mpCashApply)
    {
        try {
            List<MpCashApply> list = mpCashApplyService.selectMpCashApplyList(mpCashApply);
            ExcelUtil<MpCashApply> util = new ExcelUtil<MpCashApply>(MpCashApply.class);
            util.exportExcel(response, list, "用户申请提现记录数据","提示:\n" +
                    "1、带*号为必填项。不带*号为选填项。\n" +
                    "2、若此前该用户在系统有过代发，则银行卡号可不填写，不填写默认上次代发的银行卡号。若填写，则最终到账为填写的银行卡。\n" +
                    "3、若该用户在系统从未代发过，则银行卡号必须填写，否则导入不成功。\n" +
                    "4、该行不要删除，若删除则导入不成功。\n" +
                    "5、最大条数限制200条，超出200条需分开上传");
            mpCashApplyService.updateMpCashApplys(list);
            //默认修改待审核为已审核
        }catch (Exception e){
            log.error("用户申请提现记录发生异常",e);
        }
    }

    /**
     * 获取用户申请提现记录详细信息
     */
    @ApiOperation(value = "获取用户申请提现记录详细信息")
    @ApiImplicitParam(name="cashApplyId",value="用户申请提现记录")
    @RequiresPermissions("system:apply:query")
    @GetMapping(value = "/{cashApplyId}")
    public AjaxResult getInfo(@PathVariable("cashApplyId") Long cashApplyId)
    {
        try {
            return AjaxResult.success(mpCashApplyService.selectMpCashApplyByCashApplyId(cashApplyId));
        }catch (Exception e){
            log.error("用户申请提现记录发生异常",e);
        }
        return AjaxResult.error("用户申请提现记录异常");
    }

    /**
     * 新增用户申请提现记录
     */
    @ApiOperation(value = "新增用户申请提现记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpCashApply",value="用户申请提现记录",dataType="MpCashApply")
    })
    @RequiresPermissions("system:apply:add")
    @Log(title = "用户申请提现记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MpCashApply mpCashApply)
    {
        try {
            int i=mpCashApplyService.insertMpCashApply(mpCashApply);
            return toAjax(i);
        }catch (Exception e){
            log.error("新增用户申请提现记录发生异常",e);
        }
        return AjaxResult.error("用户申请提现记录异常");
    }


    /**
     * 修改用户申请提现记录
     */
    @ApiOperation(value = "修改用户申请提现记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpCashApply",value="用户申请提现记录",dataType="MpCashApply")
    })
    @RequiresPermissions("system:apply:edit")
    @Log(title = "用户申请提现记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MpCashApply mpCashApply)
    {
        try {
            int i=mpCashApplyService.updateMpCashApply(mpCashApply);
            return toAjax(i);
        }catch (Exception e){
            log.error("修改用户申请提现记录发生异常",e);
        }
        return AjaxResult.error("用户申请提现记录异常");
    }
    /**
     * 修改用户申请提现记录
     */
    @ApiOperation(value = "修改用户申请提现记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpCashApply",value="用户申请提现记录",dataType="MpCashApply")
    })
    @RequiresPermissions("system:apply:edit")
    @Log(title = "用户申请提现记录", businessType = BusinessType.UPDATE)
    @PostMapping("/approve")
    public AjaxResult approve(@RequestBody List<MpCashApply> mpCashApplys)
    {
        try {
            mpCashApplyService.updateMpCashApplys(mpCashApplys);
            return AjaxResult.success();
        }catch (Exception e){
            log.error("修改用户申请提现记录发生异常",e);
        }
        return AjaxResult.error("用户申请提现记录异常");
    }

    /**
     * 删除用户申请提现记录
     */
    @ApiOperation(value = "删除用户申请提现记录")
    @ApiImplicitParam(name="cashApplyIds",value="用户申请提现记录")
    @RequiresPermissions("system:apply:remove")
    @Log(title = "用户申请提现记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cashApplyIds}")
    public AjaxResult remove(@PathVariable Long[] cashApplyIds)
    {
        try {
            int i=mpCashApplyService.deleteMpCashApplyByCashApplyIds(cashApplyIds);
            return toAjax(i);
        }catch (Exception e){
            log.error("删除用户申请提现记录发生异常",e);
        }
        return AjaxResult.error("用户申请提现记录异常");
    }
}
